package com.fh.common.exceptions;


import com.fh.common.baseData.ExceptionData;
import com.fh.common.baseData.TongyiData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*  controller层的 异常统一处理   aop 的异常通知 （业务增强类）  */
@RestControllerAdvice
public class ControllerExceptions {

    /*  处理参数自定义异常*/
    @ExceptionHandler(ParamException.class)
    public TongyiData chandleParamException(Exception e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.PARAMEXCEPTIONDATA.getCode(),ExceptionData.PARAMEXCEPTIONDATA.getInfo());
    }

    /*  处理java自带的异常*/
    @ExceptionHandler(Exception.class)
    public TongyiData chandleException(Exception e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.SERVERERROR.getCode(),ExceptionData.SERVERERROR.getInfo()+": 具体信息为："+e.getMessage());
    }
    /*  处理java自带的异常*/
    @ExceptionHandler(UserNoException.class)
    public TongyiData UserNoException(UserNoException e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.USERNO.getCode(),ExceptionData.USERNO.getInfo());
    }
    /*  处理java自带的异常*/
    @ExceptionHandler(PasswordException.class)
    public TongyiData PasswordException(PasswordException e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.PASSWORDERROR.getCode(), ExceptionData.PASSWORDERROR.getInfo());
    }
    @ExceptionHandler(TokenException.class)
    public TongyiData TokenException(TokenException e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.TokenNo.getCode(), e.getMessage());
    }
    @ExceptionHandler(CountException.class)
    public TongyiData CountException(CountException e){
        e.printStackTrace();
        return TongyiData.error(ExceptionData.CountNo.getCode(), e.getMessage());
    }
}
